<!--登陆页-->


<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:include="include/admin/adminHeader::html('登陆页')">
</head>
<link href="css/bootstrapValidator.min.css" rel="stylesheet">
<script src="js/bootstrapValidator.min.js"></script>

<body>
<div class="container" id="workingArea">
    <div class="row clearfix">
        <!--导航栏-->
        <div class="col-md-12 column">
            <!--顶部导航栏-->
            <nav class="navbar  navbar-inverse " role="navigation">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse"
                            data-target="#bs-example-navbar-collapse-1"><span
                            class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span
                            class="icon-bar"></span><span class="icon-bar"></span></button>
                    <a class="navbar-brand" href="fore_home">小萝筐新闻网</a>
                </div>

            </nav>
        </div>
        <!--登陆模块-->
        <div class="col-md-12 column">
            <div class="row clearfix">
                <div class="col-md-12 column">
                    <h3 class="text-center text-info">
                        请登录
                    </h3>
                </div>
            </div>
            <div class="row clearfix">
                <div class="col-md-3 column">
                </div>
                <div class="col-md-6 column">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">用户名：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="username" v-model="bean.name"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">密码：</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="password" v-model="bean.password"/>
                            </div>
                        </div>
                        <!--<div class="form-group">-->
                        <!--<div class="col-sm-offset-2 col-sm-10">-->
                        <!--<div class="checkbox">-->
                        <!--<label><input type="checkbox" />Remember me</label>-->
                        <!--<a href="fore_register" >forgot Password?</a>-->
                        <!--</div>-->
                        <!--</div>-->
                        <!--</div>-->
                        <div class="form-group">
                            <div class="col-sm-offset-1 col-sm-10" align="center">
                                <button type="submit"  class="btn btn-primary" @click="login">登陆</button>
                                <a class="btn btn-primary" @click="register">注册</a>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="col-md-3 column">
                </div>
            </div>
        </div>
    </div>
</div>

<!--前后端交互-->
<script>
    $(document).ready(function () {
        var data4Vue = {
            uri: "user",
            bean: {id: "", name: "", password: "", realname: "", phone: "", role: ""}
        };

        var vue = new Vue({
            el: '#workingArea',
            data: data4Vue,
            mounted: function () {

            },
            methods: {
                login: function () {
                    /*bootstrap提交验证*/
                    var validator= $('form').data('bootstrapValidator').validate();
                    if(!validator.isValid()){
                        //没有通过校验
                        return;
                    } else {
                        //通过校验，可进行提交等操作
                    }
                    var url = "fore_loginPage";
                    var formdata = new FormData();
                    formdata.append("name", this.bean.name);
                    formdata.append("password", this.bean.password);
                    axios.post(url, formdata).then(function (response) {
                        console.log(response.data);
                        if (response.data.code==0) location.href = "fore_home";
                        else {
                            /*登陆失败*/

                            alert("用户名或密码错误");

//                            location.href="test";
                        }
                    })
                },
                register: function () {
                    location.href = "fore_register";
                }

            }
        });
        <!--bootstrapValidator表单验证-->

    });
</script>

<!--bootstrapValidator表单验证-->
<script>
    $(function () {
        $('form').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
//                valid: 'glyphicon glyphicon-ok',
//                invalid: 'glyphicon glyphicon-remove',
//                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                username: {
                    message: '用户名验证失败',
                    validators: {
                        notEmpty: {
                            message: '用户名不能为空'
                        }
                    }
                },
                password: {
                    validators: {
                        notEmpty: {
                            message: '密码不能为空'
                        }
                    }
                }
            }
        })
    });
</script>
</body>
</html>